package com.huafv.reggie.utils;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
/*
pom.xml
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-core</artifactId>
  <version>4.6.0</version>
</dependency>
*/

public class SMSUtils {


    public static String sendMsg(String code, String ToPhoneNumber){
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-hangzhou",
                "LTAI5tNn9sCaDJJNPtPdvEMS",
                "PASSWORD");
        IAcsClient client = new DefaultAcsClient(profile);


        SendSmsRequest request = new SendSmsRequest();
        request.setSignName("凌陌笙的小破站");
        request.setTemplateCode("SMS_462770076");
        request.setPhoneNumbers(ToPhoneNumber);
        request.setTemplateParam("{\"code\":\"" + code +"\"}");

        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
            return response.getCode();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
            return e.getErrMsg();
        }
    }

    public static void main(String[] args) {
//        SMSUtils smsUtils = new SMSUtils();
//        smsUtils.sendMsg(7894, "17585367620");
//        smsUtils.sendMsg(7894, "18184264532");

    }

}